var mysqlClient = require('../libs/mysqlClient');

function Service() {
    this.list = function (params, callback) {
        // params['u_id'] = `t_organization.id`;
        var sql = mysqlClient.buildQuerySql('t_question', params, true, true, [
            {name: 't_organization', where: 't_question.u_id=t_organization.id'}
        ]);
        mysqlClient.queryPage(sql, null, params.pageNumber, params.pageSize, callback);
    }

    this.retrieve = function (id, callback) {
        mysqlClient.getObject('t_question', {id: id}, callback);
    };
    
    this.create = function (params, callback) {
        params['u_id'] = params['*session']['id'];
        mysqlClient.addObject('t_question', params, callback);
    }
    this.update = function (id, params, callback) {
        mysqlClient.getObject('t_question', {id: id}, function (data) {
            if (data) {
                mysqlClient.updateObject('t_question', params, {id: id}, callback);
            } else {
                callback({error: '没有数据'});
            }
        });
    }
    this.delete = function (id, params, callback) {
        mysqlClient.deleteObject('t_question', {id: id}, callback);
    }
}

exports.service = Service;